package org.fast.develop.logicflow.builder;

import org.fast.develop.logicflow.core.meta.shape.LogicFlowDefinition;
import org.fast.develop.logicflow.core.meta.shape.properties.JavaClassTaskProperties;
import org.fast.develop.logicflow.core.meta.shape.task.JavaClassTask;
import org.fast.develop.logicflow.core.LogicFlowConfiguration;

/**
 * @author 莫寅
 * @createTime 2022-11-25 15:51
 * @desc：
 */
public class JavaClassTaskBuilder extends AbstractLogicFlowNodeBuilder<JavaClassTaskBuilder, JavaClassTask>{

    private String className;
    private Class taskClass;


    public JavaClassTaskBuilder(LogicFlowDefinition logicFlowDefinition, LogicFlowConfiguration logicFlowConfiguration) {
        super(logicFlowDefinition, logicFlowConfiguration);

//        if(getElement().getProperties() == null){
//            getElement().setProperties(new JavaClassTaskProperties());
//        }
    }

    @Override
    protected Class<JavaClassTask> getElementClass() {
        return JavaClassTask.class;
    }


    public String getClassName() {
        return className;
    }

    public JavaClassTaskBuilder className(String className) {
        this.className = className;
        getProperties().setClassName(className);
        return this;
    }

    public Class getTaskClass() {
        return taskClass;
    }

    public JavaClassTaskBuilder taskClass(Class taskClass) {
        this.taskClass = taskClass;
        getProperties().setClassName(taskClass.getName());
        return this;
    }

    private JavaClassTaskProperties getProperties(){
        if(getElement().getProperties() == null){
            getElement().setProperties(new JavaClassTaskProperties());
        }
        return getElement().getProperties();
    }
}
